// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App.vue'
import NProgress from 'vue-nprogress'
import {sync} from 'vuex-router-sync'
import store from './store'
import router from './router' // vue-router instance
import {TOGGLE_SIDEBAR} from 'vuex-store/mutation-types'
import Buefy from 'buefy'

Vue.use(Buefy, {
  defaultIconPack: 'fa',
  defaultContainerElement: '#content'
})
Vue.use(NProgress)
const nprogress = new NProgress({parent: '.nprogress-container'})

// Enable devtools
Vue.config.productionTip = true

sync(store, router)

const {state} = store

router.beforeEach((route, redirect, next) => {
  if (state.app.device.isMobile && state.app.sidebar.opened) {
    store.commit(TOGGLE_SIDEBAR, false)
  }
  next()
})

/* eslint-disable no-new */
const app = new Vue({
  router,
  store,
  nprogress,
  ...App
})

export {app, router, store}
